package admin.data;

import java.util.ArrayList;
import java.util.Date;

import models.CoordinaModel;
import models.DeliveryModel;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyOpts;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;

public class DeliveryData {

	private Objectify ofy;

	private String prefix = "Delivery_";
	static {
		
		try {
			ObjectifyService.register(DeliveryModel.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public DeliveryData() {		

		ObjectifyOpts opts = new ObjectifyOpts().setSessionCache(true);
		ofy = ObjectifyService.begin(opts);
	}
	
	public void insert(DeliveryModel delivery) {
		ofy.put(delivery);
	} 
	
	public ArrayList<DeliveryModel> getList(Date startTime, Date endTime) {
		ArrayList<DeliveryModel> list = new ArrayList<DeliveryModel>();
		Query<DeliveryModel> q = ofy.query(DeliveryModel.class);
		if(startTime!=null) {q.filter("created >",startTime);}
		if(endTime!=null) {q.filter("created <",endTime);}
		for (DeliveryModel delivery : q) {
			list.add(delivery);
		}
		return list;
	}
}
